<?php 
/****
author:N++
email:
license:
****/

namespace Home\Controller;
use Think\Controller;

class IndexController extends Controller{
	public function addgoods(){
		// new Home\Model\GoodsModel();//与new D('Goods');一样
		// 面向过程风格
		$GoodsModel = D('Goods');
		// $data = [
		// 	"name"	=>	"apple",
		// 	"price"	=>	10,
		// 	"color"	=>	"green"
		// ];
		// 面向属性风格
		$GoodsModel->name='orange';
		$GoodsModel->price='3.51';
		$GoodsModel->color='orange';
		if($GoodsModel->add()){
			echo "insert success.";
		}else{
			echo "insert failed.";
		}
	}

	//查询数据
	public function cha(){
		$GoodsModel = D('Goods');
		var_dump($GoodsModel->field('name,color')->where(['id'=>5])->select());
	}

	//修改数据
	public function gai(){
		$GoodsModel = D('Goods');
		print_r($GoodsModel->where('id=5')->save(['color'=>'green']));//where()->order()->limit()->delete();
	}

	//删除数据
	public function shan(){
		$GoodsModel = D('Goods');
		var_dump($GoodsModel->delete());
	}

	//测试用
	public function test(){
		echo U('Goods/test');
		exit;
		C('DB_TYPE','mongoDB');
		echo C('DB_TYPE');
		exit();
		$data=[
			'name'	=>	'alex',
			'age'	=>	'22',
		];
		$this->assign('title',$data);
		$this->display();
	}
}
?>